package com.ruoyi.web.controller.lost;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lost.bo.HyLostFoundQueryBo;
import com.ruoyi.lost.domain.HyLostFound;
import com.ruoyi.lost.service.IHyLostFoundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 失物招领管理Controller
 *
 * @author lixin
 * @date 2021-08-05
 */
@Api(value = "失物招领管理控制器", tags = {"失物招领管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/lost/found")
public class HyLostFoundController extends BaseController {

    private final IHyLostFoundService lostFoundService;

    /**
     * 查询失物招领管理列表
     */
    @ApiOperation("查询失物招领管理列表")
    @PreAuthorize("@ss.hasPermi('lost:found:list')")
    @GetMapping("/list")
    public TableDataInfo<HyLostFound> list(@Validated HyLostFoundQueryBo bo) {
        return lostFoundService.queryPageList(bo);
    }


    /**
     * 获取失物招领管理详细信息
     */
    @ApiOperation("获取失物招领管理详细信息")
    @PreAuthorize("@ss.hasPermi('lost:found:query')")
    @GetMapping("/{foundId}")
    public AjaxResult<HyLostFound> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("foundId") Long foundId) {
        return AjaxResult.success(lostFoundService.queryById(foundId));
    }

    /**
     * 新增失物招领管理
     */
    @ApiOperation("新增失物招领管理")
    @PreAuthorize("@ss.hasPermi('lost:found:add')")
    @Log(title = "失物招领管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody HyLostFound bo) {
        return toAjax(lostFoundService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改失物招领管理
     */
    @ApiOperation("修改失物招领管理")
    @PreAuthorize("@ss.hasPermi('lost:found:edit')")
    @Log(title = "失物招领管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody HyLostFound bo) {
        return toAjax(lostFoundService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除失物招领管理
     */
    @ApiOperation("删除失物招领管理")
    @PreAuthorize("@ss.hasPermi('lost:found:remove')")
    @Log(title = "失物招领管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{foundIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] foundIds) {
        return toAjax(lostFoundService.deleteWithValidByIds(Arrays.asList(foundIds), true) ? 1 : 0);
    }
}
